package com.zxy.study.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.KeyEvent;

import com.zxy.study.R;
import com.zxy.study.utils.Utils;
import com.zxy.study.adapter.TextAdapter;
import com.zxy.study.ui.behavior.UCBehavior;

import butterknife.BindView;
import butterknife.ButterKnife;


/*
 *  @项目名：  study
 *  @包名：    com.zxy.study
 *  @文件名:   UCDemoActivity
 *  @创建者:   zhangxy
 *  @创建时间:  2018/11/2 10:15
 *  @描述：    TODO
 */
public class UCDemoActivity extends Activity {

	@BindView(R.id.rv)
	RecyclerView mRecyclerView;

	UCBehavior mUCBehavior;

	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uc_demo);
		ButterKnife.bind(this);

		init();

	}

	private void init() {
		mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
		TextAdapter adapter = new TextAdapter(Utils.getTestData("嵌套滑动"));
		mRecyclerView.setAdapter(adapter);
	}

	private UCBehavior getUCBehavior() {
		if (mUCBehavior == null) {
			CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mRecyclerView.getLayoutParams();
			mUCBehavior = (UCBehavior) params.getBehavior();
		}
		return mUCBehavior;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && getUCBehavior() != null) {
			if(mUCBehavior.expandView()){
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
}
